﻿/*
 * Semaphore.h
 *
 */
#ifndef __GDK_SEMAPHORE_H__
#define __GDK_SEMAPHORE_H__

#include <gdk/core/Types.h>
#include <gdk/core/Unknown.h>

#if !defined(_WIN32)
#	include <semaphore.h>
#	include <sys/time.h>
#endif


namespace gdk
{


	class GDK_CORE_EXPORT Semaphore : virtual public Unknown
	{
		DECLARE_CLASS_HANDLE(Semaphore)
		DECLARE_CLASS_INSTANCE(Semaphore)

#ifdef _WIN32
		HANDLE			_mutex;
		HANDLE			_event;
#else
		pthread_mutex_t	_mutex;
		pthread_cond_t	_cond;
#endif
		ssize_t			_signal;


	protected:
		Semaphore(void);
		~Semaphore(void);

	public:
		ssize_t signal(void);
		ssize_t wait(uint32_t timeOut = -1, bool autoreset = false); //返回信号数量, 超时返回-1
	};




}//namespace gdk


#endif /*__GDK_SEMAPHORE_H__*/
